
public class Test {
    public static void main(String[] args) {
        String s = "   hhh   , ,   hog";
        String[] str = s.split(" ");
    }
    /*public static boolean wordPattern1(String pattern, String s) {
        StringBuilder[] sb = new StringBuilder[ch.length];
        for (int i = 0; i < ch.length; i++) {
            sb[i].append(ch[i]).append(str[i]);
        }
        for (int i = 0; i < sb.length; i++) {

        }
    }*/
    public static boolean wordPattern(String pattern, String s) {
        char[] ch = pattern.toCharArray();
        String[] str = s.split(" ");
        if(ch.length != str.length){
            return false;
        }
        for (int i = 0; i < ch.length; i++) {
            for (int j = i+1; j < ch.length; j++) {
                if(ch[i] == ch[j]){
                    if(!str[i].equals(str[j])){
                        return false;
                    }
                }else{
                    if(str[i].equals(str[j])){
                        return false;
                    }
                }
            }
        }
        return true;

    }

    public static void main5(String[] args) {
        String pattern = "abba";
        String s = "dog cat cat do";
        System.out.println(wordPattern(pattern,s));
    }
    public static void main4(String[] args) {
        StringBuilder stringBuilder = new StringBuilder("hello");
        String s = new String(stringBuilder);
    }

    public static void main3(String[] args) {
        String s = "hello";

        StringBuilder stringBuilder = new StringBuilder();

        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            stringBuilder.append(ch);
        }
    }

    public static String toLowerCase1(String s) {
        char[] ch = s.toCharArray();
        for (int i = 0; i < ch.length; i++) {
            if( ch[i]>='A' && ch[i]<='Z'){
                ch[i] += 32;
            }
        }
        return new String(ch);
    }
    public static String toLowerCase2(String s) {
        int length = s.length();
        char[] ch = new char[length];

        for (int i = 0; i < length; i++) {
            char tmp = s.charAt(i);
            if (Character.isUpperCase(tmp)) {
                ch[i] = (char)(tmp + 32);
            }else{
                ch[i] = tmp;
            }
        }
        return new String(ch);
    }
        //return stringBuilder.toString();

    public static String toLowerCase(String s) {
        StringBuilder stringBuilder = new StringBuilder();
        for(int i = 0 ;i < s.length() ;i++){
            char ch = s.charAt(i);
            if(Character.isUpperCase(ch)){
                ch += 32;
            }
            stringBuilder.append(ch);
        }
        return stringBuilder.toString();
        //return new String(stringBuilder);
    }

    public static void main2(String[] args) {
        String s = "Hello";
        System.out.println(toLowerCase(s));
    }
    public static int countSegments(String s) {
        String[] str = s.split(" ");
        int count = 0;
        for (String x : str) {
            if(!x.equals("")){
                count++;
            }
        }
        return count;
    }

    public static void main1(String[] args) {
        String s = "  abc  def, k  ";
        int n = countSegments(s);
        System.out.println(n);
    }
}
